<?php
namespace Home\Controller;

class JobController extends HomeController {

    public function index(){
    	$cate = M('TrainCate')->getField('id,name');
    	$this->assign('cate',$cate);

    	$map['onlyMember']=0;
    	$free = M('Job')->field('id,picname,trainID,position')->where($map)->order('id desc')->select();
    	foreach ($free as $key => $value) {
    		$free[$key]['cate'] = trainStrtoArr($value['trainID']);
    	}
    	$this->assign('free',$free);

    	$map['onlyMember']=1;
    	$vip = M('Job')->field('id,picname,trainID,position')->where($map)->order('id desc')->select();
    	foreach ($vip as $key => $value) {
    		$vip[$key]['cate'] = trainStrtoArr($value['trainID']);
    	}
    	$this->assign('vip',$vip);    	
    	$this->display();
    }

    public function lists(){
        $type = I('get.type');
        $trainID = I('get.trainID');

        $cate = M('TrainCate')->getField('id,name');
        $this->assign('cate',$cate);

        if ($type!='') {
            $map['onlyMember']=$type;
        }

        if ($trainID!='') {
            $map['trainID'] = array('like','%-'.$trainID.'-%');
        }
        
        $list = M('Job')->field('id,picname,trainID,position,onlyMember')->where($map)->order('id desc')->select();
        foreach ($list as $key => $value) {
            $list[$key]['cate'] = trainStrtoArr($value['trainID']);
        }
        $this->assign('list',$list);   
        $this->assign('trainID',$trainID);   
        $this->assign('type',$type);   
        $this->display();
    }

    public function detail(){
        $id = I('get.id');
        $map['id'] = $id;
        $list = M('Job')->where($map)->find();
        if (!$list) {
            $this->error('The information does not exist');
        }
        if ($list['onlyMember']==1) {
            if (!$this->loginStatus) {
                $this->error('Sorry, please login to view the full content!');
            }
        }

        $cate = M('TrainCate')->getField('id,name');
        $this->assign('cate',$cate);
        $list['cate'] = trainStrtoArr($list['trainID']);
        
        $this->assign('list',$list);

        //about Job
        $about = M('Job')->order('id desc')->limit(10)->select();
        $this->assign('about',$about);
        $this->display();
    }
   
}